<template>
<div :id="id">
  <div v-if="!gadgetSetting.transparentBackground">
    <el-card v-loading="loading"
             shadow="hover"
              class="aui-card--fill"
             :style="{height:gadgetHeight+ 'px'}"
             >
             <!-- ,backgroundImage:'url('+gadgetSetting.backgroundImg+')' style="background:no-repeat;" -->
      <div>
        <div class="cardHeader" @mouseenter="mouseenter(true)" @mouseleave="mouseenter(false)"
             v-if="(gadgetSetting.headerTitle && gadgetSetting.headerTitle.trim().length>0) || (gadgetSetting.headerDescription && gadgetSetting.headerDescription.trim().length>0)">
              <span>
                <span
                  class="cardTitle threepoints" :title="gadgetSetting.headerTitle"
                  v-if='gadgetSetting.headerTitle && gadgetSetting.headerTitle.trim().length>0'>{{ gadgetSetting.headerTitle }}</span>
                <el-tooltip :open-delay="1000" class="item"
                            effect="dark"
                            :content="gadgetSetting.headerDescription"
                            placement="right"
                            v-if='gadgetSetting.headerDescription && gadgetSetting.headerDescription.trim().length>0'>
                <i class="cuifont icon_help_circle cardIcon"></i>
              </el-tooltip>
              </span>
              <MoreMenu :slicer='slicer' :gadgetId='id' :gadgetType='gadgetInfo.com' @updateQuery="query" @fullScreen="fullScreen"/>
        </div>
        <div class="box" style="margin-top:5%">
            <el-image
              style="width: 200px; height: 130px"
              :src="gadgetSetting.backgroundImg"
              fit="contain"></el-image>
         <!-- <div class="box-text">
             <div :style="{fontSize:gadgetSetting.titleFontSize,color:gadgetSetting.titleFontColor }"
                 style="padding:5px 5px;">{{ gadgetSetting.title }}
            </div>
            <div style="margin:5px"></div>
          </div> -->
        </div>
      </div>
    </el-card>
    </div>
    <div  class="box" style="margin-top:5%;opacity:0.5;filter:alpha(opacity=50);" v-else>

    </div>
    <model :showSetting="queryModelDefaultSetting.showSetting"
           @queryModelClosed="queryModelClosed"
           :dataInfo="queryModelDefaultSetting.dataInfo"
           :updateGadget="upgradeGadgetSetting" :slicer='slicer'/>
  </div>
</template>

<script>
import mixinGadgetViewModule from '@/mixins/gadget-view-module'
// import model from '@/components/gadget/query-model/query-model.vue'
import { defaultGadgetSettingList } from '@/utils/data-json'

export default ({
  mixins: [mixinGadgetViewModule],
  components: { model: () => import('@/components/gadget/query-model/query-model') },
  data: function () {
    return {
      gadgetSetting: {},
      loading: false,
      queryModelDefaultSetting: {
        showSetting: false,
        dataInfo: {
          businessId: this.pageId,
          gadgetId: this.id,
          gadgetType: 'placeholdergadget',
          gadgetSettingExclude: ['DATA'],
          gadgetSetting: this._.find(defaultGadgetSettingList, { gadgetType: 'placeholdergadget' }).gadgetSetting

        }
      }
    }
  },
  beforeCreate () {
    // this.$options.components.model = () => import('@/components/gadget/query-model/query-model')
  },
  created () {
    this.gadgetHeight = (this.gadgetInfo.h * 20) - 20
    this.query()
    this.subscribeMessage('runReport', this.query)
    this.$store.state.isWidget = false
  },
  methods: {
    queryModelClosed () {
      this.queryModelDefaultSetting.showSetting = false
      this.query()
    },
    showQueryModel () {
      this.queryModelDefaultSetting.showSetting = true
    },
    resized (i, newH, newW, newHPx, newWPx) {
      this.gadgetHeight = (newH * 20) - 20
      this.gadgetWidth = newWPx
    },
    query () {
      this.loading = true
      this._.merge(this.gadgetSetting, this.queryModelDefaultSetting.dataInfo.gadgetSetting)
      var _self = this
      var param = {
        ...this.slicer,
        pageId: this.pageId,
        gadgetId: this.id,
        filter: this.getFilterStr()
      }
      this.$interface.reports.getReportDataInfo(param).then(({ data: res }) => {
        if (res.config) {
          _self._.merge(_self.gadgetSetting, res.config)
        }
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    }
  }
})
</script>
<style scoped>
.el-card ::v-deep .el-card__body {
  padding: 0px !important;
}

.el-card ::v-deep .el-divider--horizontal {
  margin: 3px 0 !important;
}

.threepoints {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cardHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 20px;
  border-bottom: 1px solid #eee;
  position: relative;
}

.cardHeader > span {
  display: inline-block;
  width: calc(100% - 30px);
}

.cardTitle {
  font-size: 16px;
  color: #000;
  font-weight: 700;
  display: inline-block;
  max-width: calc(100% - 30px);
  position: relative;
  top: 2px;
}

.cardIcon {
  font-size: 16px;
  font-weight: 600;
  margin-left: 10px;
  position: relative;
  top: -2px;
}

.box {
  display: flex;
  align-content: center;
  justify-content: center;
  min-width: 100px;
  min-height: 100px;

}

.box-icon {
  align-items: flex-start;
}

.box-text {
  margin: 10px 10px;
}

.img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}
</style>
